package com.tongzhan.controller;

import com.tongzhan.entity.screen.HalfYear;
import com.tongzhan.entity.screen.Month;
import com.tongzhan.entity.screen.Season;
import com.tongzhan.entity.screen.Year;
import com.tongzhan.repository.screen.HalfYearRepository;
import com.tongzhan.repository.screen.MonthRepository;
import com.tongzhan.repository.screen.SeasonRepository;
import com.tongzhan.repository.screen.YearRepository;
import com.tongzhan.utils.SqlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RequestMapping("/test")
@RestController
public class TestController {

    @Autowired
    private YearRepository yearRepository;
    @Autowired
    private HalfYearRepository halfYearRepository;
    @Autowired
    private SeasonRepository seasonRepository;
    @Autowired
    private MonthRepository monthRepository;

    @RequestMapping("/addYearData")
    public void addYearData() {
        for(int i = 2020 ; i< 2100; i ++) {
            String uuid16 = SqlUtil.getUUID16();
            Date date = new Date();
            Year year = new Year();
            year.setId(uuid16);
            year.setYear(i);
            year.setName(String.valueOf(i)+"年");
            year.setValue(String.valueOf(i));
            year.setIs_del(0);
            year.setAdd_time(date);
            year.setUpd_time(date);
            yearRepository.insertSelective(year);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

    @RequestMapping("/addHalfYearData")
    public void addHalfYearData() {
        for(int i = 2020 ; i< 2100; i ++) {
            String uuid16 = SqlUtil.getUUID16();
            Date date = new Date();
            HalfYear year = new HalfYear();
            year.setId(uuid16);
            year.setYear(i);
            year.setName(String.valueOf(i)+"年上半年");
            year.setValue(String.valueOf(i)+"-01");
            year.setIs_del(0);
            year.setAdd_time(date);
            year.setUpd_time(date);
            halfYearRepository.insertSelective(year);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String uuid162 = SqlUtil.getUUID16();
            Date date2 = new Date();
            HalfYear year2 = new HalfYear();
            year2.setId(uuid162);
            year2.setYear(i);
            year2.setName(String.valueOf(i)+"年下半年");
            year2.setValue(String.valueOf(i)+"-07");
            year2.setIs_del(0);
            year2.setAdd_time(date2);
            year2.setUpd_time(date2);
            halfYearRepository.insertSelective(year2);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

    @RequestMapping("/addSeasonData")
    public String addSeasonData() {
        for(int i = 2020 ; i< 2100; i ++) {
            String uuid16 = SqlUtil.getUUID16();
            Date date = new Date();
            Season season = new Season();
            season.setId(uuid16);
            season.setYear(i);
            season.setName(String.valueOf(i)+"年第一季度");
            season.setValue(String.valueOf(i)+"-01");
            season.setIs_del(0);
            season.setAdd_time(date);
            season.setUpd_time(date);
            seasonRepository.insertSelective(season);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String uuid162 = SqlUtil.getUUID16();
            Date date2 = new Date();
            Season season2 = new Season();
            season2.setId(uuid162);
            season2.setYear(i);
            season2.setName(String.valueOf(i)+"年第二季度");
            season2.setValue(String.valueOf(i)+"-04");
            season2.setIs_del(0);
            season2.setAdd_time(date2);
            season2.setUpd_time(date2);
            seasonRepository.insertSelective(season2);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String uuid163 = SqlUtil.getUUID16();
            Date date3 = new Date();
            Season season3 = new Season();
            season3.setId(uuid163);
            season3.setYear(i);
            season3.setName(String.valueOf(i)+"年第三季度");
            season3.setValue(String.valueOf(i)+"-07");
            season3.setIs_del(0);
            season3.setAdd_time(date3);
            season3.setUpd_time(date3);
            seasonRepository.insertSelective(season3);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String uuid164 = SqlUtil.getUUID16();
            Date date4 = new Date();
            Season season4 = new Season();
            season4.setId(uuid164);
            season4.setYear(i);
            season4.setName(String.valueOf(i)+"年第四季度");
            season4.setValue(String.valueOf(i)+"-10");
            season4.setIs_del(0);
            season4.setAdd_time(date4);
            season4.setUpd_time(date4);
            seasonRepository.insertSelective(season4);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return "完成";
    }

    @RequestMapping("/addMonthData")
    public String addMonthData() {
        for(int i = 2020 ; i< 2100; i ++) {
            String uuid16 = SqlUtil.getUUID16();
            Date date = new Date();
            Month month = new Month();
            month.setId(uuid16);
            month.setYear(i);
            month.setName(String.valueOf(i)+"年一月");
            month.setValue(String.valueOf(i)+"-01");
            month.setIs_del(0);
            month.setAdd_time(date);
            month.setUpd_time(date);
            monthRepository.insertSelective(month);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String uuid2 = SqlUtil.getUUID16();
            Date date2 = new Date();
            Month month2 = new Month();
            month2.setId(uuid2);
            month2.setYear(i);
            month2.setName(String.valueOf(i)+"年二月");
            month2.setValue(String.valueOf(i)+"-02");
            month2.setIs_del(0);
            month2.setAdd_time(date2);
            month2.setUpd_time(date2);
            monthRepository.insertSelective(month2);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String uuid3 = SqlUtil.getUUID16();
            Date date3 = new Date();
            Month month3 = new Month();
            month3.setId(uuid3);
            month3.setYear(i);
            month3.setName(String.valueOf(i)+"年三月");
            month3.setValue(String.valueOf(i)+"-03");
            month3.setIs_del(0);
            month3.setAdd_time(date3);
            month3.setUpd_time(date3);
            monthRepository.insertSelective(month3);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String uuid4 = SqlUtil.getUUID16();
            Date date4 = new Date();
            Month month4 = new Month();
            month4.setId(uuid4);
            month4.setYear(i);
            month4.setName(String.valueOf(i)+"年四月");
            month4.setValue(String.valueOf(i)+"-04");
            month4.setIs_del(0);
            month4.setAdd_time(date4);
            month4.setUpd_time(date4);
            monthRepository.insertSelective(month4);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String uuid5 = SqlUtil.getUUID16();
            Date date5 = new Date();
            Month month5 = new Month();
            month5.setId(uuid5);
            month5.setYear(i);
            month5.setName(String.valueOf(i)+"年五月");
            month5.setValue(String.valueOf(i)+"-05");
            month5.setIs_del(0);
            month5.setAdd_time(date5);
            month5.setUpd_time(date5);
            monthRepository.insertSelective(month5);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String uuid6 = SqlUtil.getUUID16();
            Date date6 = new Date();
            Month month6 = new Month();
            month6.setId(uuid6);
            month6.setYear(i);
            month6.setName(String.valueOf(i)+"年六月");
            month6.setValue(String.valueOf(i)+"-06");
            month6.setIs_del(0);
            month6.setAdd_time(date6);
            month6.setUpd_time(date6);
            monthRepository.insertSelective(month6);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String uuid7 = SqlUtil.getUUID16();
            Date date7 = new Date();
            Month month7 = new Month();
            month7.setId(uuid7);
            month7.setYear(i);
            month7.setName(String.valueOf(i)+"年七月");
            month7.setValue(String.valueOf(i)+"-07");
            month7.setIs_del(0);
            month7.setAdd_time(date7);
            month7.setUpd_time(date7);
            monthRepository.insertSelective(month7);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String uuid8 = SqlUtil.getUUID16();
            Date date8 = new Date();
            Month month8 = new Month();
            month8.setId(uuid8);
            month8.setYear(i);
            month8.setName(String.valueOf(i)+"年八月");
            month8.setValue(String.valueOf(i)+"-08");
            month8.setIs_del(0);
            month8.setAdd_time(date8);
            month8.setUpd_time(date8);
            monthRepository.insertSelective(month8);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String uuid9 = SqlUtil.getUUID16();
            Date date9 = new Date();
            Month month9 = new Month();
            month9.setId(uuid9);
            month9.setYear(i);
            month9.setName(String.valueOf(i)+"年九月");
            month9.setValue(String.valueOf(i)+"-09");
            month9.setIs_del(0);
            month9.setAdd_time(date9);
            month9.setUpd_time(date9);
            monthRepository.insertSelective(month9);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String uuid10 = SqlUtil.getUUID16();
            Date date10 = new Date();
            Month month10 = new Month();
            month10.setId(uuid10);
            month10.setYear(i);
            month10.setName(String.valueOf(i)+"年十月");
            month10.setValue(String.valueOf(i)+"-10");
            month10.setIs_del(0);
            month10.setAdd_time(date10);
            month10.setUpd_time(date10);
            monthRepository.insertSelective(month10);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String uuid11 = SqlUtil.getUUID16();
            Date date11 = new Date();
            Month month11 = new Month();
            month11.setId(uuid11);
            month11.setYear(i);
            month11.setName(String.valueOf(i)+"年十一月");
            month11.setValue(String.valueOf(i)+"-11");
            month11.setIs_del(0);
            month11.setAdd_time(date11);
            month11.setUpd_time(date11);
            monthRepository.insertSelective(month11);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            String uuid12 = SqlUtil.getUUID16();
            Date date12 = new Date();
            Month month12 = new Month();
            month12.setId(uuid12);
            month12.setYear(i);
            month12.setName(String.valueOf(i)+"年十二月");
            month12.setValue(String.valueOf(i)+"-12");
            month12.setIs_del(0);
            month12.setAdd_time(date12);
            month12.setUpd_time(date12);
            monthRepository.insertSelective(month12);
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return "完成";
    }
}
